import formPicker from '@/pages/components/form-picker.vue';
import formCheckbox from '@/pages/components/form-checkbox.vue';
import formDatetime from '@/pages/components/form-datetime.vue';
import formDate from '@/pages/components/form-date.vue';
import formCascader from '@/pages/components/form-cascader.vue';
import formButton from '@/pages/components/form-button.vue';
import formRadio from '@/pages/components/form-radio.vue';
import topSearch from '@/pages/components/top-search.vue';
import topPicker from '@/pages/components/top-picker.vue';
import selePerson from '@/pages/components/sele-person.vue';
import seleUser from '@/pages/components/sele-user.vue';
import seleShop from '@/pages/components/sele-shop.vue';
import radioItem from '@/pages/components/radio-item.vue';
import formImage from '@/pages/components/form-image.vue';

const install = function(Vue) {
    Vue.component('form-picker', formPicker);
    Vue.component('form-checkbox', formCheckbox);
    Vue.component('form-datetime', formDatetime);
    Vue.component('form-date', formDate);
    Vue.component('form-cascader', formCascader);
    Vue.component('form-button', formButton);
    Vue.component('form-radio', formRadio);
    Vue.component('top-search', topSearch);
    Vue.component('top-picker', topPicker);
    Vue.component('sele-person', selePerson);
    Vue.component('sele-user', seleUser);
    Vue.component('sele-shop', seleShop);
    Vue.component('radio-item', radioItem);
    Vue.component('form-image', formImage);
    // 自定义组件的正则
    function check(message, type) {
      switch(type) {
        case true:
          return { required: true, message };
        case 'pass':
          return { pattern: /^[a-zA-Z0-9\!\@\#\$\%\^\&\*\(\)\_\-\+\=\?\<\>]{6,20}$/, message };
        case 'phone':
          return { pattern: /^1[3456789]\d{9}$/, message };
        case 'phoneN':
          return { pattern: /^\s*$|(((0\d{2,3})-)?(\d{7,8})(-(\d{3,4}))?$|1[3456789]\d{9})$/, message };
        case 'number':
          return { validator: (value) => !isNaN(value), message };
        case 'n99':
          return { pattern: /^([0-9]|[1-9][0-9]{0,1})$/, message };
        case 'n100':
          return { pattern: /^([0-9]|[1-9][0-9]{0,1}|100)$/, message };
        case 'text20':
          return { pattern: /^([a-zA-Z0-9\u4e00-\u9fa5]){1,20}$/, message };
        case 'idcard':
          return { pattern: /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/, message };
      }
    }
    Vue.prototype.$check = check;
};

export default {
    version: '1.0.0',
    install
}
